package com.service;

import com.fegin.ItemFegin;
import com.api.OrderService;
import com.dto.ItemDTO;
import com.dto.OrderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: sksun2
 * @create: 2023-02-10
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private ItemFegin itemFegin;

    private Map<Long,OrderDTO> orderRepo = new HashMap<>();

    @PostConstruct
    public void init(){
        for (long i = 1;i<=100;i++){
            OrderDTO orderDTO = new OrderDTO();
            orderDTO.setId(i);
            orderDTO.setNum(3L);
            orderDTO.setBuyerName("买家:"+i);
            orderRepo.put(i,orderDTO);
        }
    }

    @Override
    public OrderDTO getOrderById(Long id) {
        OrderDTO orderDTO = orderRepo.get(id);
        ItemDTO item = itemFegin.getItemById(1L);
        orderDTO.setItemDTO(item);
        return orderDTO;
    }
}
